/* Let u be the vector of the center of a telescope and phi be the visibility
 * angle of the telescope. Let v be the vector of a star and theta be the 
 * angle between the star and the telescope. The star is visible in the
 * telescope if and only if theta < phi. This is equivalent to
 *
 *     u*v = |u|*|v|*cos(theta) > |u|*|v|*cos(phi),
 *
 * where u*v is vector dot-product. Since 0 <= phi <= pi/2, the right-hand 
 * side >= 0. We then require
 * 
 *     u*v > 0, and
 *     (u*v)^2 > |v|^2 * (|u|*cos(phi))^2.
 *
 * This saves us from computing the square root.
 */

#include <stdio.h>
#include <math.h>

typedef struct Point { double x, y, z; } Point, Vector;

double dot_product(Vector a, Vector b)
{
    return a.x*b.x + a.y*b.y + a.z*b.z;
}

static Vector s[500];           /* v; stars */
static Vector t[50];            /* u; telescopes */
static double d_cos_phi_sq[50]; /* (|u|*cos(phi))^2 */

int main()
{
    int num_stars, num_telescopes;
    while (scanf("%d", &num_stars) == 1 && num_stars > 0)
    {
        int num_visible = 0;
        int i, j;
        
        /* Read stars. */
        for (i = 0; i < num_stars; i++)
            scanf("%lf %lf %lf", &s[i].x, &s[i].y, &s[i].z);

        /* Read telescopes. */
        scanf("%d", &num_telescopes);
        for (j = 0; j < num_telescopes; j++)
        {
            double phi;
            scanf("%lf %lf %lf %lf", &t[j].x, &t[j].y, &t[j].z, &phi);
            d_cos_phi_sq[j] = dot_product(t[j],t[j]) * cos(phi) * cos(phi);
        }

        /* Test stars against telescopes. */
        for (i = 0; i < num_stars; i++)
        {
            for (j = 0; j < num_telescopes; j++)
            {
                double dp = dot_product(s[i], t[j]);
                if (dp > 0 && 
                    dp*dp > dot_product(s[i],s[i])*d_cos_phi_sq[j])
                    break;
            }
            if (j < num_telescopes)
                num_visible++;
        }
        printf("%d\n", num_visible);
    }
    return 0;
}